{% extends "admin/base_site.html" %}
{% load admin_modify admin_urls djblets_js djblets_utils i18n rbadmintags %}
{% load staticfiles %}


{% block global-vars %}
{{block.super}}
{%  definevar "form_id" spaceless global %}
{%   block form_id %}{{opts.model_name|default:"change"}}_form{% endblock %}
{%  enddefinevar %}
{% endblock global-vars %}


{% block page_class %}{{opts.app_label}}-{{opts.object_name.lower}}{% endblock %}
{% block page-sidebar-css-classes %}-is-connected{% endblock %}
{% block js-page-view-type %}RB.Admin.ChangeFormPageView{% endblock %}
{% block js-page-view-options %}{formID: {{form_id|json_dumps}}}{% endblock %}


{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form -is-content-flush-on-mobile{% endblock %}

{% block css %}
{{block.super}}

{%  if adminform %}
{{media.css}}
{%  elif form %}
{{form.media.css}}
{%  endif %}

<link rel="stylesheet" href="{% static 'admin/css/widgets.css' %}">
{% endblock css %}


{% block object-tools %}
{%  if change and not is_popup %}
{%   block object-tools-items %}{% endblock %}
{%  endif %}
{% endblock object-tools %}


{% block content %}

{%  block form_tag %}
<form class="rb-c-form -is-aligned"
      id="{{form_id}}"
      {% if has_file_field %}enctype="multipart/form-data"{% endif %}
      action="{{form_url|default:"."}}" method="POST">
{%  endblock form_tag %}
 {% csrf_token %}
{%  if is_popup %}
 <input type="hidden" name="_popup" value="1">
{%  endif %}

{%  block form-alerts %}
{%   if errors %}
 <div class="rb-c-alert -is-error">
  <div class="rb-c-alert__content">
   <h3 class="rb-c-alert__heading">{% spaceless %}
{%     blocktrans count counter=errors %}
    Please correct the error below.
{%     plural %}
    Please correct the errors below.
{%     endblocktrans %}
{%    endspaceless %}</h3>

{% if adminform %}
{{adminform.form.non_field_errors}}
{% elif form %}
{{form.non_field_errors}}
{% endif %}
  </div>
 </div>
{%   endif %}
{%  endblock form-alerts %}

 <div class="rb-c-page-content-box -is-content-flush">
{%  block form_content %}
{%   block form_top %}{% endblock %}

{%   block field_sets %}
{%    if adminform %}
{%     for fieldset in adminform|change_form_fieldsets %}
{%      render_change_form_fieldset fieldset %}
{%     endfor %}
{%    endif %}
{%   endblock field_sets %}

{%   block after_field_sets %}{% endblock %}

{%   block inline_field_sets %}
{%    if inline_admin_formsets %}
{%     for inline_admin_formset in inline_admin_formsets %}
{%      include inline_admin_formset.opts.template %}
{%     endfor %}
{%    endif %}
{%   endblock inline_field_sets %}

{%   block after_related_objects %}{% endblock %}
{%  endblock form_content %}

{% comment %}
 NOTE: Much of the block setup here is to satisfy compatibility with older
       versions of Review Board, with Django, and with Djblets' templates.
       Ideally, we'd replace Django's {% submit_row %} with something else,
       but that's a task for another day.
{% endcomment %}
{%  block submit_buttons_bottom %}
{%   block submit_row %}
  <div class="rb-c-form__actions">
{%    block submit_row_buttons %}
{%     if change %}{# Actual Django ChangeForm #}
{%      submit_row %}
{%     else %}
{%      include "admin/submit_line.html" with show_save=show_save|default_if_none:True show_delete_link=show_delete|default_if_none:False %}
{%     endif %}
{%    endblock submit_row_buttons %}
  </div>
{%   endblock submit_row %}
{%  endblock submit_buttons_bottom %}
 </div>
</form>
{% endblock content %}


{% block scripts-post %}
{{block.super}}

{%  if adminform %}
{{media.js}}
{%  elif form %}
{{form.media.js}}
{%  endif %}

{%  block admin_change_form_document_ready %}
<script id="django-admin-form-add-constants"
        src="{% static 'admin/js/change_form.js' %}"
        {% if adminform and add %}data-model-name="{{opts.model_name}}"{% endif %}>
</script>
{%  endblock %}

{%  prepopulated_fields_js %}
{% endblock scripts-post %}
